import { request } from './base'
// 获取用户信息
export interface UserList {
	id: number | null
	passWord: string
	userName: string
	age: number | null
	isDeleted: boolean
	creationTime: string
}

export interface UserInfo {
  id: number
  userId: string//账户
  passWord: string
  userName: string//昵称
  permissionId: string|null
  permissionName: string|null
  email: string|null
  phoneNumber: string|null
  age: number
  isDeleted: number
  creationTime: string
}
export interface UserAddInfo {
	passWord: string
	userName: string //昵称
	permissionName: string | null
	email: string | null
	phoneNumber: string | null
	age: number
	isDeleted: number
}
// 获取所有用户表单数据
export async function reqGetUserList(
	pageNum: number,
	pageSize: number
): Promise<UserInfo[]> {
	const response = await request.get('/users', {
		params: {
			pageNum,
			pageSize
		}
	})
	return response.data.data.data
}
// 处理登录请求
export async function reqLogin(
	userId: string,
	pwd: string
): Promise<any> {
	const params = new URLSearchParams({ userId, pwd }).toString()
	return await request.post('/api/user/login', params, {})
}

// 处理注册请求
export async function reqReg(
	userId: string,
	pwd: string
): Promise<any> {
	const params = new URLSearchParams({ userId, pwd }).toString()
	const response = await request.post('/api/user/reg', params, {})
	return response.data
}
// 处理删除请求
export async function reqDelete(id: number): Promise<any> {
	const response = await request.get('/user/del', {
		params: {
			id
		}
	})
	return response.data
}
//处理添加请求
export async function reqAddUser(Form: UserAddInfo): Promise<any> {
	const response = await request.post('/user/add', {
		...Form
	})
	return response.data
}

//更新用户
export async function reqUpdateUser(Form: any): Promise<any> {
  const response = await request.post('/user/update', {
    ...Form
  })
  console.log(response.data)
  return response.data
}

//根据id获取用户
export async function reqGetUserById(ids: number): Promise<UserInfo> {
  const response = await request.get('/user/findByIds', {
    params: {
      ids
    }
  })
  console.log(response.data)
  return response.data
}

//根据昵称获取用户
export async function reqGetUserByUserName(userName: string): Promise<any> {
  const response = await request.get('/user/findByUserName', {
    params: {
     userName
    }
  })
  console.log('userName'+response.data)
  return response.data
}

//根据用户名获取用户
export async function reqGetUserByUserId(userId: string): Promise<UserInfo> {
  const response = await request.get('/user/findByUserId', {
    params: {
     userId
    }
  })
  return response.data
}